<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>foreach_next测试数据</title>
</head>
<body>
<?php
/**
 * Description:
 * Author: walkskyer
 * Email:zwj_work@qq.com
 * Date: 2015/3/17
 * Time: 10:04
 */
$arr=array();
for($i=0; $i<20;$i++){
    $arr[]= "{$i}x";
}
var_dump($arr);
echo "1使用foreach的方法<br>\n";
echo "我是样式：\$k:\$v<br>\n";
foreach($arr as $k=>$v){
    echo "我是样式1：{$k}:{$v}<br>\n";
    $v=next($arr);
    if($v){
        echo "我是样式2：{$k}:{$v}<br>\n";
    }else{
        echo "there's no more info<br>\n";
    }
}
echo "存在问题：foreach和next的偏移没关系。next没有影响到foreach键的变化<br>\n";
echo "********************************************************************************************<br>\n";
echo "2使用while的方法<br>\n";
echo "我是样式：\$k:\$v<br>\n";
reset($arr);
$k=0;
while($v=current($arr)){
    echo "我是样式1：{$k}:{$v}<br>\n";
    $v=next($arr);
    if($v){
        echo "我是样式2：{$k}:{$v}<br>\n";
    }else{
        echo "there's no more info<br>\n";
    }
    /*第三条数据
     * $v=next($arr);
    if($v){
        echo "我是样式3：{$k}:{$v}<br>\n";
    }else{
        echo "there's no more info<br>\n";
    }*/
    next($arr);
    $k++;
}

echo "********************************************************************************************<br>\n";
echo "使用while方法，<br>\n";
reset($arr);
$k=0;
while($v=current($arr)):
    echo "我是样式1：{$k}:{$v}<br>\n";
    $v=next($arr);
    if($v):
        echo "我是样式2：{$k}:{$v}<br>\n";
    else:
        echo "我是样式3：there's no more info<br>\n";
    endif;
    next($arr);
    $k++;
endwhile;
?>
</body>